﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Infragistics.Controls.Menus;

namespace StartupSolution.Views.Menus.Selection
{
    public partial class XamMenuCodeBehind_Selection : Page
    {
        public XamMenuCodeBehind_Selection()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(XamMenuCodeBehind_Selection_Loaded);
        }

        void XamMenuCodeBehind_Selection_Loaded(object sender, RoutedEventArgs e)
        {
            // Create XamMenu control
            XamMenu menu = new XamMenu();

            menu.MenuOrientation = Orientation.Horizontal;
            menu.Height = 30;
            menu.Width = 400;

            menu.VerticalAlignment = VerticalAlignment.Top;
            menu.HorizontalAlignment = HorizontalAlignment.Left;

            // Create a menu item 'File'
            XamMenuItem menuItemFile = new XamMenuItem();
            menuItemFile.Header = "File";

            // Create a child menu item 'New'
            XamMenuItem menuItemFileNew = new XamMenuItem();
            menuItemFileNew.Header = "New Item";
            menuItemFile.Items.Add(menuItemFileNew);

            menu.Items.Add(menuItemFile);

            // Attach an event handler for the XamMenu ItemClicked event
            menu.ItemClicked += new EventHandler<ItemClickedEventArgs>(menu_ItemClicked);

            LayoutRoot.Children.Add(menu);
            Grid.SetRow(menu, 2);
        }

        void menu_ItemClicked(object sender, ItemClickedEventArgs e)
        {
            // TODO: Handle the XamMenu control ItemClicked event  

            XamMenuItem selectedItem = e.Item;

            // Add your custom logic here 
            if (selectedItem.Header.Equals("New Item"))
            {
                MessageBox.Show("Menu Item " + selectedItem.Header + " is clicked.");
            }
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
